class Solution {
public:
    void duplicateZeros(vector<int>& arr) {
        int left = 0;
        int right = -1;
        int sz = arr.size();

        while (right < sz - 1)
        {
            if (arr[left] != 0)
                right++;
            else
                right += 2;
            if (right < sz - 1)
                left++;
        }

        if (right >= sz)
        {
            arr[right - 1] = 0;
            right -= 2;
            left--;
        }

        while (left >= 0)
        {
            if (arr[left] != 0)
            {
                arr[right] = arr[left];
                right--;
                left--;
            }
            else
            {
                arr[right--] = arr[left];
                arr[right--] = arr[left];
                left--;
            }
        }


    }
};